package com.sc.nft.admin.rpc;

import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.dao.UserPushConfDao;
import com.sc.nft.dao.UserRelationPushCidDao;
import com.sc.nft.entity.UserPushConf;
import com.sc.nft.entity.UserRelationPushCid;
import com.sc.nft.sup.Result;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid;
import java.util.Objects;

/**
 * @author 刘国航
 * @desc
 * @since 2024/6/20 18:11
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/rpc/push")
public class PushRpc {

    private final UserRelationPushCidDao userRelationPushCidDao;
    private final UserPushConfDao userPushConfDao;

    @ApiOperation(value = "获取用户绑定cid", notes = "获取用户绑定cid", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userRelationPushCid/findByUserId", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result<String> userRelationPushCidFindByUserId(@Valid @RequestBody IdRequest idRequest) {
        UserRelationPushCid userRelationPushCid = userRelationPushCidDao.getByUserId(idRequest.getId());
        if(Objects.isNull(userRelationPushCid)) {
            return Result.success();
        }
        return Result.success(userRelationPushCid.getCid());
    }

    @ApiOperation(value = "获取用户是否开启商城订单推送", notes = "获取用户是否开启商城订单推送", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/enableMallOrderPush/findByUserId", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result<Boolean> enableMallOrderPushFindByUserId(@Valid @RequestBody IdRequest idRequest) {
        Boolean enableMallOrderPush = true;
        UserPushConf userPushConf = userPushConfDao.getByUserId(idRequest.getId());
        if(Objects.nonNull(userPushConf)) {
            enableMallOrderPush = userPushConf.getEnableMallOrderPush();
        }
        return Result.success(enableMallOrderPush);
    }

}
